/*
 * @Author: Otway
 * @Date: 2019-01-09 11:16:08
 * @LastEditors: Otway
 * @LastEditTime: 2019-08-30 18:50:09
 * @copyright: h-visions
 */
import React, { PureComponent } from 'react';
import { TableCustomize } from '../../../components/TableCustomize'
// import * as ProductionOrderService from '../../../axios/ProductionOrder'

class AddFrom3 extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      columns: [
        {
          title: '序号',
          dataIndex: 'id',
          render: (text, record, index) => <span>{(this.state.pageNum - 1) * (this.state.pageSize) + index + 1}</span>
        },
        {
          title: '机型',
          dataIndex: 'model'
        },
        {
          title: '批号',
          dataIndex: 'batchNo'
        },
        {
          title: '装配车间',
          dataIndex: 'department'
        },
        // {
        //   title: '装配机位',
        //   dataIndex: 'stationId'
        // },
        {
          title: '装配进度',
          dataIndex: 'assembleProcess'
        },
        {
          title: '试机进度',
          dataIndex: 'testMachineProcess'
        },
        {
          title: '操作',
          dataIndex: 'opts',
          render: (text, record) => <a onClick={() => this.deleteItem(record.batchNo)}>取消选择</a>
        },
      ],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      dataSource: [],
      loading: false
    }
  }
  componentDidMount() {
    this.fetch();
  }
  deleteItem = (item) => {
    this.setState({ loading: true })
    const { onSaveShiJiList } = this.props;
    const { dataSource } = this.state;
    for (var key in dataSource) {
      if (dataSource[key].batchNo === item) {
        dataSource.splice(key, 1)
      }
    }
    this.setState({ dataSource }, () => {
      setTimeout(() => {
        this.setState({ loading: false });
        onSaveShiJiList(dataSource);
      });
    })
  }
  //初始化加载数据
  fetch = (pageNum = 1, pageSize = 10) => {
    this.setState({ loading: true })
    const { searchItem, onSaveShiJiList, selectedRows } = this.props;
    searchItem.pageNum = pageNum
    searchItem.pageSize = pageSize

    this.setState({ dataSource: selectedRows, total: selectedRows.length, pageNum, pageSize, loading: false }, () => onSaveShiJiList(selectedRows))
    // ProductionOrderService.applyForQualityCheck(searchItem).then(res => {
    //   this.setState({ loading: false })
    //   if (res.data.data.code !== 200) {
    //     openModalMessage('warning', res.data.data.msg)
    //     return
    //   }
    //   this.setState({ dataSource: res.data.data.data, total: res.data.data.total, pageNum, pageSize }, () => onSaveShiJiList(res.data.data.data))
    // }).catch(err => {
    //   openModalMessage('error', err.message)
    // })
  }

  render() {
    const {
      type
    } = this.props;
    const { columns, dataSource, loading, pageNum, pageSize, total } = this.state
    return (
      <>
        <TableCustomize
          columns={columns}
          rowKey={record => record.batchNo}
          dataSource={dataSource}
          pagination={false}
          loading={loading}
          scroll={{ y: '50vh' }}
        />
        {/* <BasicPagination pageNum={pageNum} pageSize={pageSize} total={total} loadData={this.fetch} /> */}
      </>
    );
  }
}

export default AddFrom3;
